package com.renwei.yunlong.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;


/**
 */
public class TabIndicatorView extends RelativeLayout {
    private ImageView iv;
    private TextView tv_unRead;
    private TextView tv_msg;
    private int offIcon, onIcon;

    public TabIndicatorView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TabIndicatorView(Context context) {
        this(context, null);
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.tab_indicator, this);
        iv = findViewById(R.id.indicator_icon);
        tv_unRead = findViewById(R.id.bar_num);
        tv_msg = findViewById(R.id.indicator_text);
    }

    public void setIcon(int onIcon, int offIcon) {
        this.onIcon = onIcon;
        this.offIcon = offIcon;
    }

    public void setIconON() {
        iv.setImageResource(onIcon);
    }

    public void setIconOff() {
        iv.setImageResource(offIcon);
    }

    public void setUnReadNum(int num) {
        if (num == 0) {
            tv_unRead.setVisibility(View.GONE);
        } else if (num <= 99) {
            tv_unRead.setVisibility(View.VISIBLE);
            tv_unRead.setText(num + "");
        } else {
            tv_unRead.setVisibility(View.VISIBLE);
            tv_unRead.setText("99+");
        }
    }

    public void setTitle(String tab) {
        tv_msg.setText(tab);
    }

    public TextView getTilte() {
        return tv_msg;
    }

}

